﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
using System;
using System.Collections.Generic;
using Sharebert.LinkLayerLibrary.API;
using Sharebert.LinkLayerLibrary;
using Sharebert.LoggingLibrary.API;

namespace Sharebert.OverlayLibrary.API
{
    public interface IOverlay
    {
        /// <summary>
        /// Connects to the p2p network.
        /// </summary>
        void Connect();

        /// <summary>
        /// Perform a file search. This will flood the search request to all connected peers.
        /// </summary>
        /// <param name="regEx">The file regex to search for</param>
        void Search(string regEx);

        /// <summary>
        /// Respond to a file search. This will flood the search respond to all connected peers.
        /// </summary>
        /// <param name="files"></param>
        /// <param name="regEx"></param>
        /// <param name="hash"></param>
        /// <param name="downloadIp"></param>
        /// <param name="downloadPort"></param>
        void Respond(FileOffer[] files, string regEx, byte[] hash,string downloadIp, int downloadPort);

        /// <summary>
        /// Perform a clean shutdown, which informs all connected peers.
        /// </summary>
        void Offline();

        /// <summary>
        /// The IP address or hostname of the bootstrap server.
        /// </summary>
        string BootstrapServerAddress { get; }

        /// <summary>
        /// The port number of the bootstrap server.
        /// </summary>
        int BootstrapServerPort { get; }

        /// <summary>
        /// The IP address used to listen for new connections.
        /// </summary>
        string ListenAddress { get; }

        string MyIp { get; }

        /// <summary>
        /// The port number used to listen for new connections.
        /// </summary>
        int ListenPort { get; }

        /// <summary>
        /// Lower bound of active peer connections. 
        /// If the peer drops below this value he asks the bootstrap server for new peers
        /// </summary>
        int MinConnection { get; set; }

        /// <summary>
        /// Upper bound of active peer connections. 
        /// If the peer reaches this number of active peer connections, new connection attempts will be rejected.
        /// </summary>
        int MaxConnection { get; set; }

        /// <summary>
        /// Sending and receiving messages will timeout after the specified time in seconds.
        /// </summary>
        int Timeout { get; set; }

        /// <summary>
        /// Time in seconds, the peer will ping the bootstrap server.
        /// </summary>
        int BootstrapPingInverval { get; set; }

        /// <summary>
        /// Time in seconds, the peer will ping other peers.
        /// </summary>
        int PeerPingInverval { get; set; }

        /// <summary>
        /// A list of peers, this peer is currently connected to.
        /// </summary>
        ThreadSafeList<IConnection> Neighbours { get; }

        /// <summary>
        /// The logger used to log messages.
        /// </summary>
        ILogger Logger { get; }

        /// <summary>
        /// Could not connect because the bootstrap server is not available.
        /// </summary>
        event EventHandler<EventArgs> BootstrapServerIsDown;

        /// <summary>
        /// The result of a file search has been received.
        /// </summary>
        event EventHandler<SearchResultReceivedEventArgs> SearchResultReceived;

        /// <summary>
        /// Received a file search from another peer.
        /// </summary>
        event EventHandler<SearchRequestReceivedEventArgs> SearchRequestReceived;

    }
}
